﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using LGSVR.Common;
using LGSVR.BLL.Sys;

namespace LGSVR_WEB.sys
{
    public partial class messageLogList : DataBasePage
    {
        messageLogListBLL msgList = new messageLogListBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (!IsPostBack)
            {
                innit();
                gvDataBind("");
            }
        }

        private void gvDataBind(string strWhere)
        {
            int pageIndex;

            if (!string.IsNullOrEmpty(Request.QueryString["pg"]) && Utils.IsNumber(Request.QueryString["pg"]))
            {
                pageIndex = int.Parse(Request.QueryString["pg"]);
            }
            else
            {
                pageIndex = 1;
            }
            DataTable dt;
            int totalRS;

            dt = GetList("VmessageLog", " msgTitle desc ", strWhere, pageIndex, PageSize, out totalRS);
            rptBody.DataSource = dt;
            rptBody.DataBind();
            SplitHtmlCode = Split.GetHtmlCode("messageLogList.aspx", 8, pageIndex, PageSize, totalRS);
        }
        private void innit()
        {
           
            ddlgroupName.DataSource = msgList.GetgroupNameList();
            ddlgroupName.DataTextField = "groupName";
            ddlgroupName.DataValueField = "groupID";
            ddlgroupName.DataBind();

            ddlgroupName.Items.Insert(0, new ListItem("-请选择-", ""));

            ddlcardID.Items.Insert(0, new ListItem("-请选择-", ""));

           

        }
        protected void Search(object sender, CommandEventArgs e)
        {
            string strWhere = "";
            if (!string.IsNullOrEmpty(txtmsgTitle.Text.Trim()))
            {
                strWhere += " and msgTitle like '%" + txtmsgTitle.Text + "'%";
            }
             if (!string.IsNullOrEmpty(ddlgroupName.SelectedValue))
            {
                strWhere += " and groupName='" + ddlgroupName.SelectedValue +"'";

            }
            if (!string.IsNullOrEmpty(ddlcardID.SelectedValue))
            {
                strWhere += " and cardID='" + ddlcardID.SelectedValue + "'";

            }
           
            gvDataBind(strWhere);
        }

        protected void ddlgroupName_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlcardID.DataSource = msgList.GetCordIDList(ddlgroupName.SelectedValue);
            ddlcardID.DataTextField = "cardID";
            ddlcardID.DataValueField = "cardID";
            ddlcardID.DataBind();
            ddlcardID.Items.Insert(0, new ListItem("-请选择-", ""));
        }
    }
}